package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumAttributeValue;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.vo.album.AlbumInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;
	@Autowired
	private AlbumInfoService albumInfoService;

	/**
	 * 根据一级分类Id 获取全部数据
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据一级分类id获取全部分类信息")
	@GetMapping("getBaseCategoryList/{category1Id}")
	public Result<JSONObject> getBaseCategoryList(@PathVariable Long category1Id){
		JSONObject jsonObject = baseCategoryService.getBaseCategoryListByCategory1Id(category1Id);
		return Result.ok(jsonObject);
	}




	// 根据一级分类id查询下面7个指定三级数据分类
	@Operation(summary = "获取一级分类下置顶到频道页的三级分类列表")
	@GetMapping("findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>>
	findTopBaseCategory3(@PathVariable Long category1Id) {
		// 调用service
		List<BaseCategory3> list = baseCategoryService.selectTopBaseCategory3(category1Id);
		return Result.ok(list);
	}



	/**
	 * 查询所有分类数据
	 */
	@Operation(tags = "查询所有分类数据")
	@GetMapping("getBaseCategoryList")
	public Result getBaseCategoryList(){
		List<JSONObject> list = baseCategoryService.getBaseCategoryList();
		return Result.ok(list);
	}

	@Operation(tags = "根据一级分类ID 查询分类属性数据")
	@GetMapping("findAttribute/{category1Id}")
	public Result findAttribute(@PathVariable("category1Id") Long category1Id){
		//调用service
		List<BaseAttribute> list = baseCategoryService.findAttribute(category1Id);
		return Result.ok(list);
	}

	// 根据三级分类id获取一级二级id
	@Operation(summary = "根据三级分类id获取一级二级id")
	@GetMapping("getCategoryView/{category3Id}")
	public Result<BaseCategoryView> getCategoryView(@PathVariable Long category3Id){
		//调用service
		BaseCategoryView baseCategoryView = baseCategoryService.getCategoryView(category3Id);
		return Result.ok(baseCategoryView);
	}





}

